@extends('layouts.app', ['activePage' => 'course', 'titlePage' => __('课程管理')])
@section('content')
<div class="content">
  <div class="container-fluid">
      <div class="card">
          <div class="card-header card-header-primary">
            <h4 class="card-title">课程列表</h4>
            <p class="card-category"> 课程发布与管理 </p>
            {{-- <button onclick="window.location.href = 'courses/create'" class="btn btn-info btn-round float-right">
                <i class="material-icons">add</i> 新增课程
            </button> --}}
          </div>

          <div class="card-body ">

            @if (session('message'))
                <div class="row">
                  <div class="col-sm-12">
                    <div class="alert alert-success">
                      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <i class="material-icons">close</i>
                      </button>
                      <span>{{ session('message') }}</span>
                    </div>
                  </div>
                </div>
              @endif
              <div class="row justify-content-between">
                  <div class="col-md-auto mr-auto">
                    <ul class="nav">
                      <li class="nav-item">
                        <a class="nav-link active" href="?type">全部({{$all}})</a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link" href="?type=0">未发布({{$status0}})</a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link" href="?type=1">已发布({{$status1}})</a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link" href="?type=2">已下架({{$status2}})</a>
                      </li>
                    </ul>
                  </div>
                  <div class="col-auto">
                    <form class="navbar-form navbar-search" method="get">
                      <div class="input-group no-border">
                        <input type="text" name="search" class="form-control" placeholder="搜索课程...">
                        <button type="submit" class="btn btn-white btn-round btn-just-icon">
                          <i class="material-icons">search</i>
                          <div class="ripple-container"></div>
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="col-auto">
                    <a href="{{ route('courses.create') }}" class="btn btn-sm btn-primary"><i class="material-icons">add</i>新建</a>
                  </div>
                </div>

          <table class="table">
            <thead>
                <tr class="text-center text-primary">
                    <th>编号</th>
                    <th>课程名称</th>
                    <th>部位</th>
                    <th>价格</th>
                    <th>训练时间</th>
                    <th>创建时间</th>
                    <th>报名列表</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            @foreach ($courses as $course)
              <tbody>
                  <tr class="text-center">
                    <td>{{ $loop->iteration }}</td>
                      <td>{{ $course -> title}}</td>
                      <td>{{ $course-> section}}</td>
                      <td>{{ $course-> price}}&#x5143;</td>
                      <td>{{ $course->train_time}}</td>
                      <td>{{ $course->create_time}}</td>
                      <td>
                        @if ($course->status == 0)
                          <a href="#" class="alert-link text-muted">尚未发布</a>
                        @else
                          <a href="courses/{{$course->id}}/signup-list" class="alert-link">查看</a>
                        @endif
                      </td>
                      <td>
                        @switch($course->status)
                          @case('0') <span class="badge badge-info">未发布</span> @break
                          @case('1') <span class="badge badge-success">已发布</span> @break
                          @case('2') <span class="badge badge-danger">已下架</span> @break
                        @endswitch
                      </td>
                      <td class="td-actions">
                          {{-- <button type="button" rel="tooltip" class="btn btn-info" >
                              <i class="material-icons">person</i>
                          </button> --}}
                          {{-- onclick="window.location.href = 'courses/{{$course->id}}/edit'" --}}
                          {{-- onclick='swal({ title:"Good job!", text: "You clicked the button!", type: "success", buttonsStyling: false, confirmButtonClass: "btn btn-success"})' --}}
                          <button onclick="window.location.href = 'courses/{{$course->id}}/edit'" type="button" rel="tooltip" class="btn btn-success" {{ $course->status!==1?'':'disabled' }} >
                              <i class="material-icons">edit</i>
                          </button>
                          <div class="btn-group">
                            <button type="submit" rel="tooltip" class="btn btn-danger dropdown-toggle"
                            data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                              <i class="material-icons">build</i>
                            </button>
                              <div class="dropdown-menu">
                              <form method="POST" action="/courses/{{$course->id}}">
                                @method('delete')
                                @csrf
                                @if ($course->status!==1)
                                <button type="submit" class="dropdown-item">发布</button>
                                @else
                                <button type="submit" class="dropdown-item">下架</button>
                                @endif
                              </form>

                              </div>
                          </div>
                      </td>
                  </tr>
              </tbody>
            @endforeach

          </table>
          </div>
  </div>
  </div>
</div>
@endsection

